package com.explam.springboot.controller.user;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.explam.springboot.common.ResultUtil;
import com.explam.springboot.entity.Pay;
import com.explam.springboot.entity.Payway;
import com.explam.springboot.mapper.PayMapper;
import com.explam.springboot.service.IPayService;
import com.explam.springboot.service.IPaywayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/app/pay")
public class PayAppController {

    @Autowired
    private IPayService payService;

    @Resource
    private PayMapper payMapper;

    @Resource
    private IPaywayService paywayService;
    

      /*
    * 获取全部支付方式
    * */
    @GetMapping("/get-payway/all-data")
    public ResultUtil getPaywayAllData(){
        List<Payway> list = paywayService.list();
        return ResultUtil.success(list);
    }

    /*
    * 根据用户id获取12个月内每个月的总支出
    * */
    @GetMapping("/month/pay-total")
    public ResultUtil sumPayMoneyMonthTotal(@RequestParam Integer id){
        List<Map<String, Object>> payMapperMonthPayMoney = payMapper.getMonthPayAmount(id);
        return ResultUtil.success("汇总12个月内每个月的总支出", payMapperMonthPayMoney);
    }


    /*
     * 保存收入信息
     * */
    @PostMapping("/save")
    public ResultUtil savePayInfo(@RequestBody Pay pay){
        payService.saveOrUpdate(pay);
        return ResultUtil.success("保存成功");
    }

    /*
    * 统计当前月的支出
    * */
    @GetMapping("/current-month/pay-total")
    public ResultUtil sumMonthCurrentPay(@RequestParam(defaultValue = "") Integer id){
        List<Pay> pays = payMapper.currentPayByMonth(id);
        return ResultUtil.success("success", pays);
    }
}
